import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
import * as commentApi from "@/api";
export default new Vuex.Store({
  state: {
    // name: "上官端倪",
    // num: 48,
    // msg: "全歼日本大和民族，让其从地球消失，因为低劣民族不配存在于地球!",
    // products: [],
    commentlist: [],
  },
  mutations: {
    // INCREMENT(state, payload) {
    //   state.num += payload;
    // },
    // DECREMENT(state) {
    //   state.num--;
    // },
    // SET_PRODUCTS(state, payload) {
    //   state.products = payload;
    // },
    SET_COMMENT_LIST(state, payload) {
      state.commentlist = payload;
      console.log(state.commentlist);
    },
  },
  actions: {
    // GET_PRODUCTS(context) {
    //   fetch("http://chst.vip:8081/data/index.json")
    //     .then((body) => body.json())
    //     .then((res) => {
    //       console.log(res);
    //       context.commit("SET_PRODUCTS", res.data);
    //     });
    // },
    GET_COMMENT_LIST({ commit }) {
      commentApi.getComment().then((res) => {
        console.log(res);
        commit("SET_COMMENT_LIST", res.data.data);
      });
    },
  },
  getters: {
    // reverseMsg(state) {
    //   state.num = 1234;
    //   return state.msg.split("").reverse().join("");
    // },
  },
  modules: {},
});
